package dashboard.utils;

import com.bj58.argo.Argo;

public class PathUtil {
	
	private static String genPath(String prefix, Object... args) {
		if (args.length == 0) {
			return "redirect:/";
		} else {
			StringBuilder pathBuilder = new StringBuilder();
			pathBuilder.append(prefix).append(":/");
			for (Object arg : args) {
				pathBuilder.append(String.valueOf(arg)).append("/");
			}
			pathBuilder.delete(pathBuilder.length()-1, pathBuilder.length());
			return pathBuilder.toString();
		}
	}
		
	public static String redirectPath(Object...args){
		return genPath("redirect", args);
	}
	
	public static String forwardPath(Object...args){
		return genPath("forward", args);
	}
	
	private static String genPath2(String prefix, Object... args) {
		if (args.length == 0) {
			return "/";
		} else {
			StringBuilder pathBuilder = new StringBuilder();
			pathBuilder.append("/");
			for (Object arg : args) {
				pathBuilder.append(String.valueOf(arg)).append("/");
			}
			pathBuilder.delete(pathBuilder.length()-1, pathBuilder.length());
			return pathBuilder.toString();
		}
	}
	
	public static String redirectPath2(Object...args){
		return genPath2("redirect", args);
	}
	
	public static String forwardPath2(Object...args){
		return genPath2("forward", args);
	}
	
	/**
	 * 获取Argo框架的根目录
	 * @return
	 */
	public static String getArgoRootFolder(){
		return Argo.getConfigFolder();
	}
	
	/**
	 * 获取Argo框架namespace的目录
	 * @return
	 */
	public static String getArgoNamespaceFolder(){
		String Argopath = Argo.getConfigFolder();
		if(Argopath!=null && Argopath.endsWith("/")){
			Argopath = Argo.getConfigFolder()+Argo.getNamespace();
		}else{
			Argopath = Argo.getConfigFolder()+"/"+Argo.getNamespace();
		}
		return Argopath;
	}
	
	/**
	 * 获取Argo框架的scf的lib包目录
	 * @return
	 */
	public static String getSCFlibFolder(){
		String Argopath = Argo.getConfigFolder();
		if(Argopath!=null && Argopath.endsWith("/")){
			Argopath = Argo.getConfigFolder()+"scf_lib";
		}else{
			Argopath = Argo.getConfigFolder()+"/scf_lib";
		}
		return Argopath;
	}
}